package com.example.assignment2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Activity1 extends ActionBarActivity implements OnClickListener {

	private Button activity2;
	private Button activity3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity1);

		activity2 = (Button) findViewById(R.id.openActivity2);
		activity2.setOnClickListener(this);

		activity3 = (Button) findViewById(R.id.openActivity3);
		activity3.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {

		case R.id.openActivity2:
			intent = new Intent(this, Activity3.class);
			break;
		case R.id.openActivity3:
			intent = new Intent(this, Activity3.class);
			break;

		default:
			break;
		}

		if (intent != null) {
			startActivity(intent);
			finish();
		}
	}
}
